package person.bing.fbcloud.leetcode;

/**
 * @author: mengfanbing
 * @date: 2020/8/19 9:23
 */
public class Q647 {
    public static void main(String[] args) {
        String param = "abc";
        int ans = countSubstrings(param);
        System.out.println(ans);
    }
    public static int countSubstrings(String s) {
        int ans = 0;
        int length = s.length();
        for (int i=0;i<length;i++){
            for (int j=i+1;j<length+1;j++){
                if (s.substring(i,i+1).equals(s.substring(j-1,j))){
                    String substring = s.substring(i, j);
                    if (isPalindrome(substring)){
                        ans++;
                    }
                }
            }
        }
        return ans;
    }
    private static Boolean isPalindrome(String param){
        int start = 0;
        int end = param.length()-1;
        while (start < end){
            if (param.substring(start,start+1).equals(param.substring(end,end+1))){
                start++;
                end--;
            }else {
                return false;
            }
        }
        return true;
    }

}
